package com.liu.sx.common.util;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class ChannelHolder {

    private static final Map<String, Channel> clientSession =new ConcurrentHashMap<String,Channel>();


    public static void addClient(String clientId,Channel Channel){

        clientSession.put(clientId,Channel);
    }

    public static Channel getChannelId(String clientId){
        return  clientSession.get(clientId);
    }

    public static void removeChannelId(String clientId){
        clientSession.remove(clientId);
    }

    public static  Map getAllClient(){
        return  clientSession;
    }


    public static void removeClientId(Channel channel){

        for(String key : clientSession.keySet()){
            if (clientSession.get(key).id().asLongText().equalsIgnoreCase(channel.id().asLongText())){

                clientSession.remove(key);
            }
        }
    }





}
